import request from '@/utils/axios'

// 用户分配角色
export interface PermissionAssignUserRoleReqType {
  userId: number
  roleIds: number[]
}

// 角色分配菜单权限
export interface PermissionAssignRoleMenuReqType {
  roleId: number
  menuIds: number[]
}

// 角色分配数据权限
export interface PermissionAssignRoleDataScopeReqType {
  roleId: number
  dataScope: number
  dataScopeDepartIds: number[]
}

// 角色分配用户
export interface PermissionAssignRoleUserReqType {
  roleId: number
  userIds: number[]
}

/**
 * 权限相关接口
 */
export const PermitApi = {
  // 查询
  Search: {
    // 用户拥有的角色列表
    userRoleList: (userId: number) => {
      return request.get({ url: '/system/permission/list-user-roles?userId=' + userId, is_mock: true })
    },
    // 角色拥有的菜单权限
    roleMenuList: (roleId: number) => {
      return request.get({ url: '/system/permission/list-role-menus?roleId=' + roleId, is_mock: true })
    },
    // 角色拥有的用户列表
    roleUserList: (roleId: number) => {
      return request.post({ url: '/Role/roleuser', data: { id: roleId } })
    }
  },
  // 赋予
  Assign: {
    // 赋予用户角色
    userRole: (data: PermissionAssignUserRoleReqType) => {
      return request.post({ url: '/system/permission/assign-user-role', data, is_mock: true })
    },
    // 赋予角色菜单权限
    roleMenu: (data: PermissionAssignRoleMenuReqType) => {
      return request.post({ url: '/system/permission/assign-role-menu', data, is_mock: true })
    },
    // 赋予角色数据权限
    roleDataScope: (data: PermissionAssignRoleDataScopeReqType) => {
      return request.post({ url: '/system/permission/assign-role-data-scope', data, is_mock: true })
    },
    // 赋予角色用户
    roleUser: (data: PermissionAssignRoleUserReqType) => {
      return request.post({
        url: '/Role/getuser',
        data: {
          rid: data.roleId,
          uid: data.userIds
        }
      })
    }
  }
}
